<!DOCTYPE html>
<html>
<head>
<#include "/admin/common/common.ftl" parse=true encoding="utf-8">
<link href="${base}/scripts/ckeditor/skins/moono/editor.css" type="text/css" rel="stylesheet">
</head>
<body class="hold-transition skin-blue sidebar-mini">
	<div class="wrapper">

		<#include "/admin/common/header.ftl" parse=true encoding="utf-8">

		<!-- Content Wrapper. Contains page content -->
		<div class="content-wrapper">
			<!-- Content Header (Page header) -->
			<section class="content-header">
				<h1>课程管理</h1>
				<ol class="breadcrumb">
					<li class="active">添加新章</li>
				</ol>
			</section>

			<!-- Main content -->
			<section class="content">
				<!-- Info boxes -->
				<div class="row">
					<div class="box">
						<div class="box-header">
							<div class="table-btn">
								<a href="${base}/admin/course/${course.id!}/chapter/list.do">
									<span class="label label-primary">章列表</span>
								</a>
							</div>
						</div>
						<!-- /.box-header -->
						<div class="box-body">
						<form class="form-horizontal" role="form" name="defaultForm" id="defaultForm" method="post" action="#">
							<div class="form-group">
										<label class="col-md-2 control-label">课程名称</label>
										<div class="col-md-8">
											<input class="form-control" type="text" rows="10"  disabled="disabled" value="${course.name!}">
										</div>
									</div>
								<div class="form-group">
									<label class="col-md-2 control-label">章名称</label>
									<div class="col-md-8">
										<input id="name" name="name" class="form-control" type="text" rows="10" placeholder="请输入章名称">
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">章描述</label>
									<div class="col-md-8">
										<textarea class="form-control" rows="8" id="describe" placeholder="请输入章描述" name="describe"></textarea>
									</div>
								</div>
								<div class="form-group">
									<div class="col-sm-offset-3 col-sm-3">
										<button type="submit" class="btn btn-primary">添加</button>
										<button type="submit" class="btn btn-primary" onclick="returnChapterList('${course.id!}')">返回</button>
									</div>
								</div>
							</form>
						</div>
						<!-- /.box-body -->
					</div>
					<!-- /.box -->
				</div>
				<!-- /.row -->
			</section>
			<!-- /.content -->
		</div>
		<!-- /.content-wrapper -->

	</div>
	<!-- ./wrapper -->
	<#include "/admin/common/footer.ftl" parse=true encoding="utf-8">
</body>
<script type="text/javascript">

function returnChapterList(courseId){
	window.location.href = "${base}/admin/course/"+courseId+"/chapter/list.do";
}


		
	$('#defaultForm')
			.bootstrapValidator(
					{
						message : '该项不能为空',
						live : 'disabled',
						feedbackIcons : {
							valid : 'glyphicon glyphicon-ok',
							invalid : 'glyphicon glyphicon-remove',
							validating : 'glyphicon glyphicon-refresh'
						},

						submitHandler : function(validator, form, submitButton) {
							if (window.confirm("确定要添加？")) {
								var url = "${base}/admin/course/"+${course.id!}+"/chapter/addnewAction.json";
								var entity = {
									name : $("#name").val(),
									describe : $("#describe").val()
								};
								var onloadFunc = function(result) {
									if (result.isSuccess == true) {
										alert('添加成功');
										window.location = "${base}/admin/course/"+${course.id!}+"/chapter/list.do";
									} else {
										alert(result.message);
									}
								};
								httpRequestPostJson(url, entity, false,
										onloadFunc);
							} else {
								return;
							}
						},
						fields : {
							name : {
								validators : {
									notEmpty : {
										message : '章名称不能为空'
									}
								}
							},
							describe : {
								validators : {
									notEmpty : {
										message : '章描述不能为空'
									}
								}
							}
						}
					});
</script>
</html>